#include <semaphore.h>
#include <stdio.h>
#include <pthread.h>

sem_t space, prod;

int amount = 10;

void * producer(void *p)
{
    while(amount--){
       sem_wait(&space);
        printf("Put a product\n");
        sem_post(&prod);
    } 
    return NULL;
}

void * consumer(void *p){
    while(1){
        sem_wait(&prod);
        printf("Gets a product\n");
        sem_post(&space);
    }  
     return NULL;
}

int main(void)
{
    sem_init(&space, 0, 1); 
    sem_init(&prod, 0, 0);
    pthread_t tid[2];
    pthread_create(&tid[0], NULL, producer, NULL);
    pthread_create(&tid[1], NULL, consumer, NULL);
    sem_destroy(&space);  
    sem_destroy(&prod); 
    pthread_join(tid[0], NULL);
    return 0;
}